package com.example.softwareengg;




import java.io.DataOutputStream;
import java.net.Socket;

import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.content.Intent;


public class ScreenSettings extends HeaderFooter implements OnClickListener{
	String ipadd;
	
String ipdefault = "127.0.0.1";
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ViewGroup vg = (ViewGroup) findViewById(R.id.lldata);
        ViewGroup.inflate(ScreenSettings.this, R.layout.screensetting, vg);
        TextView userName1 = (TextView)findViewById(R.id.textUsername);
        	
        
      	
        String shruti2="";
		//Intent i1 = getIntent();
        if((MyOverridenApp.getUser().trim()).equals(""))
        	shruti2= "Welcome user";
        if(!((MyOverridenApp.getUser().trim()).equals("")))
		shruti2 = "Welcome " +MyOverridenApp.getUser();
        
		TextView SetHead = (TextView) findViewById(R.id.sethead);
		Button browse = (Button)findViewById(R.id.setip);
		SpannableString content1 = new SpannableString(" Your Settings");
		SpannableString content2 = new SpannableString(shruti2);
		content1.setSpan(new UnderlineSpan(), 0, content1.length(), 0);
		content2.setSpan(new UnderlineSpan(), 0, content2.length(), 0);
		userName1.setText(content2);
		Button button_logout = (Button) findViewById(R.id.Button_logout);
		SetHead.setText(content1);
		Button home = (Button) findViewById(R.id.home);
		browse.setOnClickListener(this);
		button_logout.setOnClickListener(this);
		home.setOnClickListener(this);
		
	}
	 public void onClick(View v) {
	        switch (v.getId()) {
	        
	        case R.id.home:
	        {
				   Intent intent = new Intent(ScreenSettings.this,ScreenA.class);
				    startActivity(intent);
				    break;

	        }
	      	        case R.id.setip:
	      	        
	      	        {
	      	        	EditText serverIP = (EditText) findViewById(R.id.editipadd);
	      	        	
	      	        	MyOverridenApp.setserverIP(serverIP.getText().toString());
	      	        	Toast.makeText(getApplicationContext(),MyOverridenApp.getserverIP(), Toast.LENGTH_LONG).show();
	      	        	Intent intent = new Intent(ScreenSettings.this,ScreenA.class);
	  				    startActivity(intent);
	      	        	
	      	        }

	      	    	  
	 				    break;
	      	      case R.id.Button_logout:
	  	        {
	  	        	try{
	  	        	Socket client = MyOverridenApp.getClient();
	  	        	DataOutputStream outToServer = new DataOutputStream(client.getOutputStream());
	  				
	  				outToServer.writeBytes("signout\n");
	  				client.close();
	  				}
	  	        	catch(Exception e){
	  	        		e.printStackTrace();
	  	        	}
	  				   Intent intent = new Intent(ScreenSettings.this,ScreenA.class);
	  				    startActivity(intent);
	  				    break;

	  	        }
	 				    
	        	        default:
	            break;
	        }


	

	 }
	 @Override
	 public void onBackPressed() {
	 }

}